﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using elfam.web.Dao;
using elfam.web.Models;
using elfam.web.Paging;
using elfam.web.Paging.Prototype;
using NHibernate;
using NHibernate.Criterion;
using Order = NHibernate.Criterion.Order;
using SearchCriteria = elfam.web.Paging.SearchCriteria;

namespace elfam.web.Controllers
{
    public class TestController : BaseController
    {
        //
        // GET: /Test/

        public ActionResult List(SearchCriteria request)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof (Income));
            criteria.AddOrder(request.GetOrder());
            criteria.CreateAlias("Product", "Product");
            request.Criteria = criteria;
            TableModel<Income> tableModel = TableModel<Income>.Build(request, "/Test/List/");
            return View(tableModel);
        }

        public ActionResult Bind(TestBind bind)
        {
            return View();
        }

        public ActionResult QueryBuilder(ProductListAdminSearchCriteria criteria)
        {
            ProductListAdminQueryBuilder queryBuilder = new ProductListAdminQueryBuilder(criteria);
            var result = queryBuilder.Execute(daoTemplate.Session);
            return View(result);
        }

    }

    public class TestBind
    {
        private int a;
        public int b;
        public int c { get; private set; }
        public int d { get; set; }
    }
}
